﻿#ifndef DOU_GPU_INSTANCING
#define DOU_GPU_INSTANCING

// 矩阵缓冲
StructuredBuffer<float4x4> transformBuf;

/**
 * 获取 Instancing 的矩阵
 */
float4x4 GetInstancingTransform(const uint instanceId)
{
    float4x4 trans = transformBuf[instanceId];
    // 去掉矩阵中额外存储的数据，避免后续的运算出现异常
    trans[3][0] = 0;
    trans[3][1] = 0;
    return trans;
}

/**
 * 获取 Instancing 顶点世界坐标
 */
float4 GetInstancingWorldPosition(const float3 input, const uint instanceId)
{
    return mul(GetInstancingTransform(instanceId), float4(input.xyz, 1));
}

float4 GetInstancingWorldPosition(const float4 input, const uint instanceId)
{
    return mul(GetInstancingTransform(instanceId), input);
}

#endif
